//
//  BN_NoticeHelperTest.m
//  BabyNow
//
//  Created by 闫建刚 on 14-5-11.
//  Copyright (c) 2014年 iMobile. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "XCTestAsync.h"
#import "BN_NoticeHelper.h"

@interface BN_NoticeHelperTest : XCTestCase
{
    BN_NoticeHelper *helper_;
}

@end

@implementation BN_NoticeHelperTest

- (void)setUp
{
    [super setUp];
    // Put setup code here. This method is called before the invocation of each test method in the class.
    helper_ = [[BN_NoticeHelper alloc]init];
}

- (void)tearDown
{
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    [super tearDown];
    helper_ = nil;
}

- (void)xctAssertNil:(NSString *)errorMsg{
    XCTAssertNil(errorMsg);
}

- (void)xcAsyncSuccess{
    XCAsyncSuccess();
}

// 测试删除通知
- (void)testRemoveNoticeByIdAsync{
    NSString *noticeId = @"1";
    [helper_ removeNoticeWithId:noticeId completeHandler:^(id result, NSString *errMsg) {
        __weak typeof(self) weakSelf = self;
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"删除通知的结果:%@",result);
            [weakSelf xcAsyncSuccess];
        }
    }];
}

// 测试收藏通知
- (void)testCollectNoticeByIdAsync{
    NSString *noticeId = @"9";
    [helper_ collectNoticeWithId:noticeId completeHandler:^(id result, NSString *errMsg) {
        __weak typeof(self) weakSelf = self;
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"收藏通知的结果:%@",result);
            [weakSelf xcAsyncSuccess];
        }
        
    }];
}

// 测试赞通知
- (void)testSupportNoticeByIdAsync{
    NSString *noticeId = @"71";
    int flg = 1;
    [helper_ supportNoticeWithId:noticeId flg:flg completeHandler:^(id result, NSString *errMsg) {
        __weak typeof(self) weakSelf = self;
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"赞通知的结果:%@",result);
            [weakSelf xcAsyncSuccess];
        }

    }];
}

// 测试回复通知
- (void)testReplyNoticeByIdAsync{
    
    NSString *noticeId = @"9";
    
    [helper_ replyNoticeWithId:noticeId replyContent:@"2014-05-12 pm 3:45 回复编号为9的通知" completeHandler:^(id result, NSString *errMsg) {
        __weak typeof(self) weakSelf = self;
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"回复通知结果:%@",result);
            [weakSelf xcAsyncSuccess];
        }
    }];
}

// 测试查询通知列表
- (void)testQueryNoticeListAsync{
    __weak typeof(self) weakSelf = self;
    helper_.queryNoticeListHandler = ^(id result,NSString *errorMsg){
        if (errorMsg) {
            [weakSelf xctAssertNil:errorMsg];
        }else{
            NSLog(@"通知列表:%@",result);
            [weakSelf xcAsyncSuccess];
        }
    };
    [helper_ refreshNoticeList];
}

// 测试查询通知详情
- (void)testQueryNoticeDetailAsync{
    __weak typeof(self) weakSelf = self;
    NSString *noticeId = @"16";
    [helper_ queryNoticeDetailWithId:noticeId completeHandler:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"通知详情:%@",result);
            [weakSelf xcAsyncSuccess];
        }
    }];
}

// 测试发布通知
- (void)testPostNoticeAsync{
    __weak typeof(self) weakSelf = self;

    NSString *subject = @"测试通知";
    NSString *content = @"2014-06-30 上午班级测试帐户发布带图片的通知";
    
    /*NSString *fileName1 = @"parent.png";
    NSString *imgPath1 = [[NSBundle mainBundle]pathForResource:@"parent" ofType:@"png"];
    NSString *mimeType1 = [IMB_FileHelper mimeType:imgPath1];
    NSLog(@"image1 -> mimeType:%@",mimeType1);
    NSData *imgData1 = [NSData dataWithContentsOfFile:imgPath1];*/
    
    NSString *fileName2 = @"ios8.png";
    NSString *imgPath2 = [[NSBundle mainBundle]pathForResource:@"ios8" ofType:@"png"];
    NSString *mimeType2 = [IMB_FileHelper mimeType:imgPath2];
    NSLog(@"image2 -> mimeType:%@",mimeType2);
    NSData *imgData2 = [NSData dataWithContentsOfFile:imgPath2];
    
    NSString *fileName3 = @"1.png";
    NSString *imgPath3 = [[NSBundle mainBundle]pathForResource:@"1" ofType:@"png"];
    NSString *mimeType3 = [IMB_FileHelper mimeType:imgPath2];
    NSLog(@"image3 -> mimeType:%@",mimeType2);
    NSData *imgData3 = [NSData dataWithContentsOfFile:imgPath3];
    
    NSString *fileName4 = @"jeep.jpg";
    NSString *imgPath4 = [[NSBundle mainBundle]pathForResource:@"jeep" ofType:@"jpg"];
    NSString *mimeType4 = [IMB_FileHelper mimeType:imgPath2];
    NSLog(@"image4 -> mimeType:%@",mimeType4);
    NSData *imgData4 = [NSData dataWithContentsOfFile:imgPath4];
    
    /*NSString *mp4FileName4 = @"parent.mp4";
    NSString *mp4FilePath4 = [[NSBundle mainBundle]pathForResource:@"parent" ofType:@"mp4"];
    NSString *mp4MimeType4 = [IMB_FileHelper mimeType:imgPath2];
    NSLog(@"mp4 -> mimeType:%@",mp4MimeType4);
    NSData *mp4FileData4 = [NSData dataWithContentsOfFile:imgPath2];*/
    
    
    // 封装一张图片
    NSArray *fileInfoArr = @[
                             //@{kFileName:fileName1,kFileData:imgData1,kFileMimeType:FILE_MIME_TYPE_FOR_PNG}
                             //,
                             //@{kFileName:fileName2,kFileData:imgData2,kFileMimeType:FILE_MIME_TYPE_FOR_PNG}
                             //,
                             @{kFileName:fileName3,kFileData:imgData3,kFileMimeType:FILE_MIME_TYPE_FOR_PNG}
                             /*,
                             @{kFileName:fileName4,kFileData:imgData4,kFileMimeType:FILE_MIME_TYPE_FOR_PNG}*/
                             ];
    
    [helper_ postNoticeWithSubject:subject content:content fileInfoArr:fileInfoArr completeHandler:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"测试发布通知结果：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    } uploadProcessingHandler:^(double process) {
        NSLog(@"进度:%f",process);
    }];
    
}


@end
